

The files in this section present the current state of the microcode.
The files have datecode 261106 (today), but they are the same as the microcode in the software
pack (ucode260211), because there have been no changes since then.

For getting your board running, you only need the ucode260211 file.


The first file is "microcode 261106.txt".

In a hackaday log I describe the microcode file and the microcode generator:
https://hackaday.io/project/190345-isetta-ttl-computer/log/217942-first-6502-microcode

But the method to run the code at a w3Schools page will not work any more. But I think with some effort,
you could get the generator to run, because it's interfaces are quite simple.

As you know, microcode is organized in pages. Each (even) page can hold 256 instructions (of 16 steps each).

The file has a section for each instruction. At the end of the file, it has a table for each page.
(some pages are merged into one, so page_in and page_ix map to the same page, with same page number).
The table has the instructions (in 16x16 grid), and for each instruction it mentions, in hex, directly below it,
the amount of cycles that the instruction takes. This is most easily seen in "page nr 2" that has the 6502 opcodes.
These maps can be used to see if there are unused instruction codes, that could be used for new instructions.
But beware, some instructions have more than 16 cycles (number higher than 0x10), and that means that the instruction
also uses space from the next instruction, so that next instruction is not free to use !

(If you want to add your own processor microcode, it would be best to use one or more fully free pages for that. 
The pages 26, 28 and 30 are still free. You could also re-define the 6502 instructions at page 2.
The z80 instructions should be left untouched, z80 code is used to start-up the system from the SD card.)


Note that the microcode has several "*** error ***" messages, but (I hope) all these positions were checked, and the
message should not have been produced at that locations (error is no problem there).

The second file is "microcode Javascript 261106.txt". This is the Javascript source that generates the
microcode.
At the end of the script, you find all instructions for each processor. For each instruction, there is a
function call to a part of the generator. You should be able to track how the cycles for each instruction are
generated, but I advice you to start with simple instructions.

There are a few more Javascript files, not present here, because they first need a clean-up because it 
contains a lot of garbage from old projects.



The microcode actually does a lot more than implementing a processor. Some of it's other functions are:
Startup:
 - system reset  (keyword "R E S E T" )
 - initialize tables (keyword tbl1)
 - copy Z80 boot code from microcode flash to RAM at 0xE000 (keyword DATA, prepared by function "init_values")
 - init system variables (keyword launch)
 - transfer control to bootcode at 0xE000 (end of launch)
Peripherals:
 - process timer interrupt every scanline
 - keyboard and mouse communication
 - video display driver
 - sound driver
 - rtc real time clock
Specialized processing:
 - Blitter
 - Sound generator

The HW reset signal sets instruction and page both to 0, so system reset starts at instruction 0 in page 0.

The Z80 boot code comes from a Z80 assembler, and it is put in the Javascript "memory" array at 0xE000. From there,
a javascript function generates the microcode that will reproduce this code after reset. A problem here was, that
within the microcode you can only use a few literals (like 0, 1, 8, 32 and it's combinations). To obtain an arbitrary
literal byte, you need up to three microcode instructions, to construct the value using shift-left, or, inc or dec.
And these few literals are just memory-resident registers that are initialized to that value (and never change).
There are a few more literals, like reg_128 (0x80), reg_0F (0x0F), lit4 (0x04), lit16 (0x10).
To be able to produce all 256 bytes in a single microcode, at first 64 mem-based registers are filled with even values from 0-126.
When loading, odd values are then obtained by setting the carry-in of the ALU, and values above 127 are obtained by adding 128 (the
value 128 is kept in the T register). After the data value is loaded, it is written to memory with the PC as auto-incrementing pointer.
This is done for all thousands of data values that together represent the Z80 boot code.


If you want to get the javascript running, you should know:

You should first call "build_microcode". 
It builds rtc, blitter color conversions, 6502, z80 and blitter functions. 

Then call "build_reset". 
It does Isetta startup functions, i/o and device drivers.

"processortype" and "processor_z80" are only used to check if the bootcode is ment for the Z80, to 
select the correct processor type. There is a single position where there is a check if they are equal.
 You can just modify the code so this check always returns true.

To get output from the javascript, you might have to modify the "function commentline(str)", that writes to
a certain HTML textbox.